<template>
  <div>
    <el-dialog
      :title="form.id ? '编辑管理员' : '添加管理员'"
      :visible.sync="isshow"
      @close="reset"
    >
      <el-form :model="form" :rules="rules" ref="memberForm">
        <el-form-item label="手机号" :label-width="formLabelWidth" prop="phone">
          <el-input
            clearable
            v-model="form.phone"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="昵称"
          :label-width="formLabelWidth"
          prop="nickname"
        >
          <el-input
            clearable
            v-model="form.nickname"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input
            show-password
            clearable
            type="password"
            v-model="form.password"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-switch
            v-model="form.status"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="2"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="reset">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { memberedit, memberinfo } from "../../request/api";
import { mapActions } from "vuex";
export default {
  props: ["pageData"],
  data() {
    return {
      isshow: false,
      dialogTableVisible: false,
      formLabelWidth: "120px",
      form: {
        nickname: "",
        phone: "",
        password: "",
        status: 2,
      },
      rules: {
        nickname: [{ required: true, message: "请输入昵称", trigger: "blur" }],
        phone: [{ required: true, message: "请输入手机号", trigger: "blur" }],
      },
    };
  },
  methods: {
    ...mapActions("member", ["getMemberList"]),
    reset() {
      this.isshow = false;
      this.$refs.memberForm.resetFields();
      this.form = {
        nickname: "",
        phone: "",
        password: "",
        status: 2,
      };
    },
    submitForm() {
      this.$refs.memberForm.validate((val) => {
        if (!val) {
          return;
        }
        memberedit(this.form).then((res) => {
          if (res.code == 200) {
            this.$message.success(res.msg);
            this.getMemberList(this.pageData);
            this.reset();
            return;
          }
        });
      });
    },
    getInfo(uid) {
      this.isshow = true;
      memberinfo({ uid }).then((res) => {
        if (res.code == 200) {
          this.form = res.list;
          this.form.password = "";
        }
      });
    },
  },
};
</script>

<style scoped>
</style>